package com.yangluyao.jsr303.hibernate.validator.common.impl;

import com.yangluyao.jsr303.hibernate.validator.common.Rest;
import lombok.Data;

import java.io.Serializable;

/**
 * @author YLY
 * @ClassName HttpResult
 * @Date 2020/7/29
 * @Version 1.0.2
 */
@Data
public class HttpResult<T> implements Rest<T>, Serializable {
    private static final long serialVersionUID = -7616216747521482608L;
    private int httpStatus = 200;
    private String message = "";
    private T data;
    private String identifier = "";

    /**
     * OK Rest
     * @param message
     * @return
     */
    public static Rest ok(String message,int httpStatus){
        HttpResult result = new HttpResult<>();
        result.setMessage(message);
        result.setHttpStatus(httpStatus);
        return result;
    }
    /**
     * OK Data
     * @param data
     * @return
     */
    public static <T> Rest<T> ok(T data,String message,int httpStatus){
        HttpResult result = new HttpResult<>();
        result.setHttpStatus(httpStatus);
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    /**
     * error
     * @param message
     * @param httpStatus
     * @param identifier
     * @return
     */
    public static Rest error(String message,int httpStatus,String identifier){
        HttpResult result = new HttpResult<>();
        result.setHttpStatus(httpStatus);
        result.setIdentifier(identifier);
        result.setMessage(message);
        return result;
    }
}
